<template>
  <u-container-layout>
    <zlrt-table :p="ctx">
      <template #before>
        <zlrt-search :p="ctx">
        </zlrt-search>
        <div class="tool-bar">
          <el-button type="danger" v-hasPermit="['wms-order:sale:del']" icon="Delete" :disabled="!ctx.selected.length"
            @click="ctx.batchDelete()">
            批量删除
          </el-button>
          <span style="float:right">
            <el-button type="success" v-hasPermit="['wms-order:sale:list']" :loading="ctx.exportLoading" icon="Download"
              @click="ctx.export()">
              导出
            </el-button>
            <el-button type="primary" v-hasPermit="['wms-order:sale:save']" icon="Plus" @click="ctx.showEdit()">
              添加
            </el-button>
          </span>
        </div>
      </template>
      <template #status="scope">
        {{ ctx.other.getStatusName(scope.row.status) }}
      </template>
      <template #createOn="scope">
        {{ ctx.other.formatDt(scope.row.createOn) }}
      </template>
      <template #operation="scope">
        <el-button type="primary" v-hasPermit="['wms-order:sale:save']" link size="small" icon="Edit" v-if="scope.row.status === '0'"
          @click="ctx.showEdit(scope.row)">
          明细
        </el-button>
        <el-button type="primary" v-hasPermit="['wms-order:sale:detail']" link size="small" icon="Edit" v-if="scope.row.status === '99' || scope.row.status === '100'"
          @click="ctx.showEdit(scope.row)">
          发货申请
        </el-button>
        <el-button v-hasPermit="['wms-order:sale:del']" type="danger" link size="small" icon="Delete"
          @click="ctx.del(scope.row.id)">
          删除
        </el-button>
      </template>
      <template #after>
        <el-dialog v-model="ctx.editVisible" title="销售单明细" width="90%" append-to-body
          :close-on-click-modal="false" @close="ctx.closeEdit()">
          <el-form :ref="(e) => ctx.formRef = e" :model="ctx.editData" :rules="ctx.rules" v-loading="ctx.editLoading"
            label-width="120px" class="demo-ruleForm">
            <el-table :data="ctx.editData.orderGoodsList" style="width: 100%;margin-top: 10px;"
              @selection-change="ctx.other.handleGoodsSelectionChange">
              <el-table-column type="selection" width="55" />
              <el-table-column prop="projectName" label="项目"></el-table-column>
              <el-table-column prop="skuName" label="物料名称" width="250">
                <template #default="scope">
                  {{ scope.row.skuName }}
                </template>
              </el-table-column>
              <el-table-column prop="serialNumber" label="出厂编号" width="200"></el-table-column>
              <el-table-column prop="barCode" label="物料编码" width="150"></el-table-column>
              <el-table-column prop="specification" label="规格型号" width="200">
                <template #default="scope">
                  {{ scope.row.specification || '-'}}
                </template>
              </el-table-column>
              <el-table-column prop="number" label="数量" width="100">
              </el-table-column>
              <el-table-column prop="unit" label="单位" width="100">
              </el-table-column>
            </el-table>
          </el-form>
          <template #footer>
            <span class="dialog-footer">
              <el-button @click="ctx.editVisible = false">取消</el-button>
              <el-button v-if="ctx.editData.status === '0'" type="success" @click="ctx.other.pass()">审核通过</el-button>
              <el-button v-else type="primary" @click="ctx.other.selectGoods()">发货申请</el-button>
            </span>
          </template>
        </el-dialog>
      </template>
    </zlrt-table>
  </u-container-layout>
</template>

<script lang="ts" src="./sale" />

<style lang="scss" scoped>

</style>
